//
//  MenuViewController.swift
//  ExpressDriver
//
//  Created by sheng on 2017/11/16.
//  Copyright © 2017年 sheng. All rights reserved.
//

import UIKit

class MenuViewController: UIViewController,UITableViewDelegate, UITableViewDataSource {
    
    let headerViewH: CGFloat = 200
    
    var dataArray = [["Change Password","password_icon"],["Submit Ticket","ticket"],["Contact US","phone_icon"],["File Management","file"]]
    
    
    

    override func viewDidLoad() {
        super.viewDidLoad()
        self.view.backgroundColor = UIColor.white

        view.addSubview(headerView)
        view.addSubview(tableView)
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    
    private lazy var tableView: UITableView = {
        
        let tab = UITableView(frame: CGRect(x: 0, y: self.headerViewH, width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height - self.headerViewH), style: .plain)
        tab.backgroundColor = UIColor(colorLiteralRed: 13.0 / 255.0, green: 184.0 / 255.0, blue: 246.0 / 255.0, alpha: 1.0)
        tab.separatorStyle = UITableViewCellSeparatorStyle.none
        tab.contentInset = UIEdgeInsets(top: 20, left: 0, bottom: 0, right: 0)
        tab.delegate = self
        tab.dataSource = self
        let nib = UINib(nibName: String(describing: MenuCell.self), bundle: nil)
        tab.register(nib, forCellReuseIdentifier: "menuCell")
        tab.estimatedRowHeight = 44.0
        tab.rowHeight = UITableViewAutomaticDimension
        return tab
    }()
    
    
    private lazy var headerView: UIView = {
        let view = UIView(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: self.headerViewH))
        let bgImageView = UIImageView(frame: view.frame)
        bgImageView.image = UIImage(named: "sidebar_bg")
        bgImageView.contentMode = UIViewContentMode.scaleAspectFill
        bgImageView.clipsToBounds = true
        view.addSubview(bgImageView)
        return view
    }()
    
    
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return dataArray.count
    }
    
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        
        let cell = tableView.dequeueReusableCell(withIdentifier: "menuCell", for: indexPath) as! MenuCell
        cell.selectionStyle = .none
        cell.label.text = dataArray[indexPath.row][0]
        cell.titleImage.image = UIImage(named: dataArray[indexPath.row][1])
        return cell
    }
    
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        tableView.deselectRow(at: indexPath, animated: true)
        
        switch indexPath.row {
        case 0:
            let changeController = ChangePasswordController()
            changeController.title = "Change Password"
            DrawerViewController.shareDrawer?.LeftViewController(didSelectController: changeController)
        case 3:
            let fileController = FileManagerController()
            fileController.title = "File Management"
            DrawerViewController.shareDrawer?.LeftViewController(didSelectController: fileController)
        default:
            break;
        }       
    }

    

}
